<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/3/21
 * Time: 11:57
 */
namespace app\admin\controller;
use think\ Controller;
use think\Db;
class ApiinformationController extends CommonController
{
    /*---------------资讯start---------------*/
    /**
     * getInformationData 获取资讯信息
     * type
     * @param $page 页码
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return 数组
     */
    public function getInformationData(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }

        $where = array();
//        if(isset($lat) && isset($lon) && $lat && $lon){
//            $where['lat'] = $lat;
//            $where['lon'] = $lon;
//        }
        $where['life_new_type'] = $type;
        $where['index_user_id'] = $user_id;
        $data = $this->getLifeData($type,$where,$page);
        return json_encode(['status'=>200,"msg"=>$data]);
    }


    /**
     * getInformationDetail 单条资讯详情
     * @param $life_id 资讯id
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return 数组
     */
    public function getInformationDetail(){
        header("Access-Control-Allow-Origin:*");
        extract(input());
        if($user_id !=0){
            $auth = $this->checkAll($user_id,$time,$value,$reqKey);
            if($auth == false){
                $returnData['status'] = 301;
                $returnData['msg'] = "Token失效！请重新登录！";
                return json_encode($returnData);
            }
        }
        $type = Db::table('ew_life')->where('life_id',$life_id)->value('life_new_type');
        if($type == 4){
            $data = Db::table('ew_life')
                ->alias ('el')
                ->join('ew_life_type elt','el.life_type=elt.lt_id','left')
                ->where('life_id',$life_id)
                ->field('el.life_id,life_new_type,life_message,life_zan,el.life_number,el.life_title,el.life_content,el.life_image,el.life_time,elt.lt_id,elt.lt_name')
                ->find();
        }else{
            $data = Db::table('ew_life')->alias ('el')
                ->join('ew_u_user uu','el.life_user_id=uu.user_id','left')
                ->join('ew_area u','el.life_sheng=u.district_id','LEFT')
                ->join('ew_area ua','el.life_shi=ua.district_id','LEFT')
                ->join('ew_area uaa','el.life_qu=uaa.district_id','LEFT')
                ->where('life_id',$life_id)
                ->field('user_id,user_image,user_username,u.district sheng,ua.district shi,uaa.district qu,el.*')
                ->find();
        }
        if($data['life_image']){
            $data['life_image'] = trim($data['life_image'],',');
            $data['life_image'] = explode(',',$data['life_image']);
        }else{
            $data['life_image'] = array();
        }
        Db::table('ew_life')->where('life_id',$life_id)->setInc('life_number');//访问量加1
        $zan = Db::table('ew_life_zan')
            ->where('lz_user_id',$user_id)
            ->where('lz_life_id',$life_id)
            ->find();
        if($zan){
            $data['zan'] = 2;//已经点赞
        }else{
            $data['zan'] = 1;//没有点赞
        }
        return json_encode(['status'=>200,"msg"=>$data]);
    }
    /**
     * 单条资讯详情数据——评论数据
     * life_id，page
     * @return string
     */
    public function lifeDataInfoMessage(){
        header("Access-Control-Allow-Origin:*");
        extract(input());
        if($user_id !=0){
            $auth = $this->checkAll($user_id,$time,$value,$reqKey);
            if($auth == false){
                $returnData['status'] = 301;
                $returnData['msg'] = "Token失效！请重新登录！";
                return json_encode($returnData);
            }
        }
        $field = 'u.user_id one_id,u2.user_id reply_id,u.user_username one_name,u2.user_username reply_name';
        $field .= ',lm_content,lm_time,u.user_image one_image,u2.user_image reply_image';
        $field .= ',lm_zan,lm_id';
        $data = Db::table('ew_life_message')->alias('m')
            ->join('ew_u_user u','m.lm_one_user_id=u.user_id','LEFT')
            ->join('ew_u_user u2','m.lm_reply_user_id=u2.user_id','LEFT')
            ->where('lm_life_id',$life_id)
            ->field($field)
            ->limit(($page-1)*10,10)
            ->select();
        if($data){
            foreach ($data as $k=>$v){
                $data[$k]['iszan'] = 0;
                $have = Db::table('ew_life_message_zan')
                    ->where('ll_life_message_zan',$v['lm_id'])
                    ->where('ll_user_id',$user_id)
                    ->find();
                if($have){
                    $data[$k]['iszan'] = 1;
                }
            }
        }
        return json_encode(['status'=>200,'msg'=>$data]);
    }
    /**
     * 直接评论资讯的
     * @return string
     */
    public function insertLmOne(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        // 启动事务
        Db::startTrans();
        try{
            $data = array();
            $data['lm_one_user_id'] = $user_id;
            $data['lm_life_id'] = $life_id;
            $data['lm_content'] = $content;
            $data['lm_time'] = date('Y-m-d H:i:s');
            Db::table('ew_life_message')->insert($data);
            //========================
            Db::table('ew_life')
                ->where('life_id',$life_id)
                ->setInc('life_message');
            //========================

            // 提交事务
            Db::commit();
            $tc = Db::table('ew_life')->where('life_id',$life_id)->value('life_new_type');
            if($tc != 4){
                $whoid = Db::table('ew_life')->where('life_id',$life_id)->value('life_user_id');
                $name = Db::table('ew_u_user')->where('user_id',$user_id)->value('user_username');
                $tc = $tc+5;
                $this->sendJpush("$whoid","{$name}回复了您",array('aa'=>'bb'),1,$tc);
            }

            return json_encode(['status'=>200,'msg'=>'成功']);
            //=====end===============
        } catch (\Exception $e) {
            Db::rollback();
            return json_encode(['status'=>0,'msg'=>'失败']);
        }
    }
    /**
     * 评论资讯的回复的回复
     * @return string
     */
    public function insertLmTwo(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        // 启动事务
        Db::startTrans();
        try{
            $data = array();
            $data['lm_one_user_id'] = $uid;
            $data['lm_reply_user_id'] = $user_id;
            $data['lm_life_id'] = $life_id;
            $data['lm_content'] = $content;
            $data['lm_time'] = date('Y-m-d H:i:s');
            Db::table('ew_life_message')->insert($data);
            //========================
            Db::table('ew_life')
                ->where('life_id',$life_id)
                ->setInc('life_message');
            //========================

            /*-----------------加入消息表------------------*/
//            $notice = array();
//            $notice['n_where'] = 3;//加一个：4
//            //备用：如果也需要给发布人提醒的话就两条
//            //$need = Db::table('ew_circle')->where('circle_id',$circle_id)->value('circle_user_id');
//            $time = date('Y-m-d H:i:s');
//            $notice['n_time'] = $time;
//            $notice['n_user_id'] = $uid;//给谁留言
//            $notice['n_reply_user_id'] = $user_id;//谁留言
//            $notice['n_life_id'] = $life_id;//哪个动态（如果推加个字段）
//            $notice['n_title'] = "在{$time}的时候给您回复了，回复内容：{$content}";
//            Db::table('ew_notice')->insert($notice);
            /*----------------------end------------------*/

            // 提交事务
            Db::commit();
            /*-----------推送和透传------------*/
            $name = Db::table('ew_u_user')->where('user_id',$user_id)->value('user_username');
            $tc = Db::table('ew_life')->where('life_id',$life_id)->value('life_new_type');
            $tc = $tc+5;
            $this->sendJpush("$uid","{$name}回复了您",array('aa'=>'bb'),1,$tc);
            /*-----------end------------*/
            return json_encode(['status'=>200,'msg'=>'成功']);
            //=====end===============
        } catch (\Exception $e) {
            Db::rollback();
            return json_encode(['status'=>0,'msg'=>'失败']);
        }
    }
    /**
     * 点赞或者取消点赞
     * life_id
     * @return string
     */
    public function zanStatus(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $who = Db::table('ew_life')->where('life_id',$life_id)->value('life_user_id');
        // 启动事务
        Db::startTrans();
        try{
            $res = Db::table('ew_life_zan')
                ->where('lz_life_id',$life_id)
                ->where('lz_user_id',$user_id)
                ->find();
            if($res){
                Db::table('ew_life_zan')
                    ->where('lz_life_id',$life_id)
                    ->where('lz_user_id',$user_id)
                    ->delete();
                Db::table('ew_life')
                    ->where('life_id',$life_id)
                    ->setDec('life_zan');
                Db::table('ew_u_user')->where('user_id',$who)->setDec('user_zan');
            }else{
                Db::table('ew_life_zan')
                    ->insert(['lz_life_id'=>$life_id,'lz_user_id'=>$user_id]);
                Db::table('ew_life')
                    ->where('life_id',$life_id)
                    ->setInc('life_zan');
                Db::table('ew_u_user')->where('user_id',$who)->setInc('user_zan');
            }
            //========================
            // 提交事务
            Db::commit();
            return json_encode(['status'=>200,'msg'=>'成功']);
            //=====end===============
        } catch (\Exception $e) {
            Db::rollback();
            return json_encode(['status'=>0,'msg'=>'失败']);
        }
    }
    /**
     * 收藏或者取消收藏资讯
     * life_id
     * @return string
     */
    public function attentionJob(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }

        $res = Db::table('ew_attention_life')
            ->where('al_user_id',$user_id)
            ->where('al_life_id',$life_id)
            ->find();
        if($res){
            $res2 = Db::table('ew_attention_life')
                ->where('al_user_id',$user_id)
                ->where('al_life_id',$life_id)
                ->delete();
        }else{
            $res2 = Db::table('ew_attention_life')
                ->insert(['al_user_id'=>$user_id,'al_life_id'=>$life_id]);
        }
        if($res2){
            return json_encode(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json_encode(['status'=>0,'msg'=>'操作失败']);
        }
    }

    /*---------------资讯end---------------*/

    /*---------------发布start---------------*/
    /**
     * ReleaseMyJob 发布个人招聘
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string
     */
    public function releaseMyJob(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        // || $qu=="" || $job_address=="" || $job_phone =="" || $job_content==""
        if($job_name=="" || $sheng == "" || $shi==""){
             return json_encode(['status'=>110,'msg'=>"信息不完整！"]);
        }else{
            $data = [
                'job_user_id'=>$user_id,
                'job_name'=>$job_name,
                'job_money_min'=>$money,
                'job_money_max'=>$money,
                'job_age_min'=>$age_min,
                'job_age_max'=>$age_max,
                'job_peple'=>$job_peple,
                'job_com_find_zhouqi'=>$zhouqi,//1长期 2短期
                'job_zhouqi_year'=>$zhouqi_time,
                'job_sheng'=>$sheng,
                'job_shi'=>$shi,
                'job_qu'=>$qu,
                'job_address'=>$job_address,
                'job_school'=>$job_school,
                'job_year'=>$job_year,
                'job_sex'=>$job_sex,
                'job_phone'=>$job_phone,
                'job_weixin'=>$job_weixin,
                'job_qq'=>$job_qq,
                'job_content'=>$job_content,
                'job_type'=>1,
                'job_createtime'=>date("Y-m-d H:i:s"),
                'job_lat'=>$lat,//加三个
                'job_lon'=>$lon,
                'job_zhouqi_order'=>$job_zhouqi_order,
                'job_beautiful'=>trim($beautiful,','),
                'job_whatfor'=>$job_whatfor
            ];
            if(isset($url)){
                $data['job_url'] = $url;
            }
            $res = Db::table('ew_job')->insert($data);
            if($res){
                return json_encode(['status'=>200,"msg"=>"发布成功！"]);
            }else{
                return json_encode(['status'=>110,"msg"=>"发布失败！"]);
            }
        }

    }
    public function releaseMyJobUpdate(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        if($job_name=="" || $sheng == "" || $shi==""){
            return json_encode(['status'=>110,'msg'=>"信息不完整！"]);
        }else{
            $data = [
                'job_user_id'=>$user_id,
                'job_name'=>$job_name,
                'job_money_min'=>$money,
                'job_money_max'=>$money,
                'job_age_min'=>$age_min,
                'job_age_max'=>$age_max,
                'job_peple'=>$job_peple,
                'job_com_find_zhouqi'=>$zhouqi,//1长期 2短期
                'job_zhouqi_year'=>$zhouqi_time,
                'job_sheng'=>$sheng,
                'job_shi'=>$shi,
                'job_qu'=>$qu,
                'job_address'=>$job_address,
                'job_school'=>$job_school,
                'job_year'=>$job_year,
                'job_sex'=>$job_sex,
                'job_phone'=>$job_phone,
                'job_weixin'=>$job_weixin,
                'job_qq'=>$job_qq,
                'job_content'=>$job_content,
                'job_type'=>1,
                'job_createtime'=>date("Y-m-d H:i:s"),
                'job_lat'=>$lat,//加三个
                'job_lon'=>$lon,
                'job_zhouqi_order'=>$job_zhouqi_order,
                'job_beautiful'=>trim($beautiful,','),
                'job_whatfor'=>$job_whatfor
            ];
            if(isset($url)){
                $data['job_url'] = $url;
            }
            $res = Db::table('ew_job')->where('job_id',$job_id)->update($data);
            if($res){
                return json_encode(['status'=>200,"msg"=>"发布成功！"]);
            }else{
                return json_encode(['status'=>110,"msg"=>"发布失败！"]);
            }
        }

    }

    /**
     * ReleaseEnterpriseJob 发布企业招聘
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string
     */
    public function releaseEnterpriseJob(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        // || $qu=="" || $job_address=="" || $job_phone =="" || $job_content=="" || $com_name=="" || $com_sheng=="" || $com_shi==""|| $com_qu=="" || $com_address==""
        if($job_name=="" || $sheng == "" || $shi==""){
            return json_encode(['status'=>110,'msg'=>"信息不完整！"]);
        }else{
            $data = [
                'job_user_id'=>$user_id,
                'job_name'=>$job_name,
                'job_money_min'=>$money,
                'job_money_max'=>$money,
                'job_age_min'=>$age_min,
                'job_age_max'=>$age_max,
                'job_peple'=>$job_peple,
                'job_sheng'=>$sheng,
                'job_shi'=>$shi,
                'job_qu'=>$qu,
                'job_address'=>$job_address,
                'job_school'=>$job_school,
                'job_year'=>$job_year,
                'job_sex'=>$job_sex,
                'job_com_find_zhouqi'=>$zhouqi,//1长期 2短期
                'job_zhouqi_year'=>$zhouqi_time,
                'job_phone'=>$job_phone,
                'job_weixin'=>$job_weixin,
                'job_qq'=>$job_qq,
                'job_content'=>$job_content,
                'job_type'=>2,
                'job_createtime'=>date("Y-m-d H:i:s"),
                'job_com_name'=>$com_name,
                'job_com_jianjie'=>$com_jianjie,
                'job_com_sheng'=>$com_sheng,
                'job_com_shi'=>$com_shi,
                'job_com_qu'=>$com_qu,
                'job_com_address'=>$com_address,
                'job_lat'=>$lat,//加三个
                'job_lon'=>$lon,
                'job_zhouqi_order'=>$job_zhouqi_order,
                'job_beautiful'=>trim($beautiful,','),
                'job_zhi'=>$job_zhi
            ];
            if(isset($url)){
                $data['job_url'] = $url;
            }
            $res = Db::table('ew_job')->insert($data);
            if($res){
                return json_encode(['status'=>200,"msg"=>"发布成功！"]);
            }else{
                return json_encode(['status'=>110,"msg"=>"发布失败！"]);
            }
        }
    }
    public function releaseEnterpriseJobUpdate(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        if($job_name=="" || $sheng == "" || $shi=="" || $qu==""){
            return json_encode(['status'=>110,'msg'=>"信息不完整！"]);
        }else{
            $data = [
                'job_user_id'=>$user_id,
                'job_name'=>$job_name,
                'job_money_min'=>$money,
                'job_money_max'=>$money,
                'job_age_min'=>$age_min,
                'job_age_max'=>$age_max,
                'job_peple'=>$job_peple,
                'job_sheng'=>$sheng,
                'job_shi'=>$shi,
                'job_qu'=>$qu,
                'job_address'=>$job_address,
                'job_school'=>$job_school,
                'job_year'=>$job_year,
                'job_sex'=>$job_sex,
                'job_com_find_zhouqi'=>$zhouqi,//1长期 2短期
                'job_zhouqi_year'=>$zhouqi_time,
                'job_phone'=>$job_phone,
                'job_weixin'=>$job_weixin,
                'job_qq'=>$job_qq,
                'job_content'=>$job_content,
                'job_type'=>2,
                'job_createtime'=>date("Y-m-d H:i:s"),
                'job_com_name'=>$com_name,
                'job_com_jianjie'=>$com_jianjie,
                'job_com_sheng'=>$com_sheng,
                'job_com_shi'=>$com_shi,
                'job_com_qu'=>$com_qu,
                'job_com_address'=>$com_address,
                'job_lat'=>$lat,//加三个
                'job_lon'=>$lon,
                'job_zhouqi_order'=>$job_zhouqi_order,
                'job_beautiful'=>trim($beautiful,','),
                'job_zhi'=>$job_zhi
            ];
            if(isset($url)){
                $data['job_url'] = $url;
            }
            $res = Db::table('ew_job')->where('job_id',$job_id)->update($data);
            if($res){
                return json_encode(['status'=>200,"msg"=>"发布成功！"]);
            }else{
                return json_encode(['status'=>110,"msg"=>"发布失败！"]);
            }
        }
    }
    /**
     * findJob 找活干
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string
     */
    public function findJob(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        //|| $qu=="" || $job_address=="" || $job_phone =="" || $job_content==""
        if($job_name=="" || $sheng == "" || $shi==""){
            return json_encode(['status'=>110,'msg'=>"信息不完整！"]);
        }else{
            $data = [
                'job_user_id'=>$user_id,
                'job_name'=>$job_name,
                'job_money_min'=>$money,
                'job_money_max'=>$money,
                'job_age_min'=>$age_min,
                'job_age_max'=>$age_max,
                'job_peple'=>$job_peple,
                'job_sheng'=>$sheng,
                'job_shi'=>$shi,
                'job_qu'=>$qu,
                'job_address'=>$job_address,
                'job_school'=>$job_school,
                'job_year'=>$job_year,
                'job_sex'=>$job_sex,
                'job_com_find_zhouqi'=>$zhouqi,//1长期 2短期
                'job_zhouqi_year'=>$zhouqi_time,
                'job_phone'=>$job_phone,
                'job_weixin'=>$job_weixin,
                'job_qq'=>$job_qq,
                'job_content'=>$job_content,
                'job_type'=>3,
                'job_createtime'=>date("Y-m-d H:i:s"),
                'job_lat'=>$lat,//加三个
                'job_lon'=>$lon,
                'job_zhouqi_order'=>$job_zhouqi_order,
                'job_beautiful'=>trim($beautiful,',')
            ];
            if(isset($url)){
                $data['job_url'] = $url;
            }
            $res = Db::table('ew_job')->insert($data);
            if($res){
                return json_encode(['status'=>200,"msg"=>"发布成功！"]);
            }else{
                return json_encode(['status'=>110,"msg"=>"发布失败！"]);
            }
        }
    }
    public function findJobUpdate(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        if($job_name=="" || $sheng == "" || $shi==""){
            return json_encode(['status'=>110,'msg'=>"信息不完整！"]);
        }else{
            $data = [
                'job_user_id'=>$user_id,
                'job_name'=>$job_name,
                'job_money_min'=>$money,
                'job_money_max'=>$money,
                'job_age_min'=>$age_min,
                'job_age_max'=>$age_max,
                'job_peple'=>$job_peple,
                'job_sheng'=>$sheng,
                'job_shi'=>$shi,
                'job_qu'=>$qu,
                'job_address'=>$job_address,
                'job_school'=>$job_school,
                'job_year'=>$job_year,
                'job_sex'=>$job_sex,
                'job_com_find_zhouqi'=>$zhouqi,//1长期 2短期
                'job_zhouqi_year'=>$zhouqi_time,
                'job_phone'=>$job_phone,
                'job_weixin'=>$job_weixin,
                'job_qq'=>$job_qq,
                'job_content'=>$job_content,
                'job_type'=>3,
                'job_createtime'=>date("Y-m-d H:i:s"),
                'job_lat'=>$lat,//加三个
                'job_lon'=>$lon,
                'job_zhouqi_order'=>$job_zhouqi_order,
                'job_beautiful'=>trim($beautiful,',')
            ];
            if(isset($url)){
                $data['job_url'] = $url;
            }
            $res = Db::table('ew_job')->where('job_id',$job_id)->update($data);
            if($res){
                return json_encode(['status'=>200,"msg"=>"发布成功！"]);
            }else{
                return json_encode(['status'=>110,"msg"=>"发布失败！"]);
            }
        }
    }
    /*---------------发布end---------------*/


    /*---------------新增三个发布资讯---------------*/
    /**
     * 三个通用：新增（备用：联系方式，电话，微信）
     * 1 新农村，2 大学生，3 二手货
     * @return string
     */
    public function newVillage(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        if($title=="" || $sheng == "" || $shi==""){
            return json_encode(['status'=>110,'msg'=>"信息不完整！"]);
        }else{
            $price = sprintf("%.1f",$price,0,-1);
            $data = [
                'life_user_id'=>$user_id,
                'life_title'=>$title,
                'life_sheng'=>$sheng,
                'life_shi'=>$shi,
                'life_qu'=>$qu,
                'life_address'=>$address,
//                'life_lat'=>$lat,
//                'life_lon'=>$lon,
                'life_image'=>trim($image,','),
                'life_time'=>date("Y-m-d H:i:s"),
                'life_content'=>$content,
                'life_new_type'=>$type,
                'life_price'=>$price,
                'life_phone'=>$phone,
                'life_weixin'=>$weixin,
                'life_thing'=>$thing,
            ];
            if(isset($url)){
                $data['life_url'] = $url;
            }
            $res = Db::table('ew_life')->insert($data);
            if($res){
                return json_encode(['status'=>200,"msg"=>"发布成功！"]);
            }else{
                return json_encode(['status'=>110,"msg"=>"发布失败！"]);
            }
        }
    }
    /**
     * 三个通用：编辑
     * @return string
     */
    public function updateVillage(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        if($title=="" || $sheng == "" || $shi==""){
            return json_encode(['status'=>110,'msg'=>"信息不完整！"]);
        }else{
            $price = sprintf("%.1f",$price,0,-1);
            $data = [
                'life_user_id'=>$user_id,
                'life_title'=>$title,
                'life_sheng'=>$sheng,
                'life_shi'=>$shi,
                'life_qu'=>$qu,
//                'life_lat'=>$lat,
//                'life_lon'=>$lon,
                'life_address'=>$address,
                'life_image'=>trim($image,','),
                'life_time'=>date("Y-m-d H:i:s"),
                'life_content'=>$content,
                'life_price'=>$price,
                'life_phone'=>$phone,
                'life_weixin'=>$weixin,
                'life_thing'=>$thing,
            ];
            if(isset($url)){
                $data['life_url'] = $url;
            }
            $res = Db::table('ew_life')->where('life_id',$life_id)->update($data);
            if($res){
                return json_encode(['status'=>200,"msg"=>"修改成功！"]);
            }else{
                return json_encode(['status'=>110,"msg"=>"修改失败！"]);
            }
        }
    }
    /**
     * 删除我发布的新增三个
     * life_id
     * @return string
     */
    public function deleteMy(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $res = Db::table('ew_life')
            ->where('life_id',$life_id)
            ->delete();
        if($res){
            return json_encode(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json_encode(['status'=>0,'msg'=>'操作失败']);
        }
    }
    /*---------------新增三个发布end---------------*/




}